package com.mtons.datastructure.tree.binarytree;

import com.mtons.datastructure.tree.bplustree.BPlusTree;

import java.util.Random;

public class BinaryTreeTest {

    public static void main(String[] args) {
        BinaryTree bt = new BinaryTree();
        bt.insert(50);
        bt.insert(20);
        bt.insert(80);
        bt.insert(10);
        bt.insert(30);
        bt.insert(60);
        bt.insert(90);
        bt.insert(25);
        bt.insert(85);
        bt.insert(500);
        bt.insert(100);

        System.out.println("MAX : " + bt.findMax().data);
        System.out.println("MIN : " + bt.findMin().data);

//        bt.delete(10);//删除没有子节点的节点
//        bt.delete(30);//删除有一个子节点的节点
//        bt.delete(80);//删除有两个子节点的节点
//
//        System.out.println("MAX : " + bt.findMax().data);
//        System.out.println("MIN : " + bt.findMin().data);

        System.out.println("前序遍历 : ");
        bt.preOrder(bt.find(80));
//        System.out.println("中序遍历 : ");
//        bt.preOrder(bt.find(100));
//        System.out.println("后序遍历 : ");
//        bt.preOrder(bt.find(100));
    }

    private static void testRandomInsert(int size) {
        BinaryTree tree = new BinaryTree();
        System.out.println("\nTest random insert " + size + " datas");
        Random random = new Random();
        int randomNumber = 0;
        long current = System.currentTimeMillis();
        for (int i = 0; i < size; i++) {
            randomNumber = random.nextInt(size * 10);
            System.out.print(randomNumber + " ");
            tree.insert(randomNumber);
        }
        long duration = System.currentTimeMillis() - current;
        System.out.println("time elpsed for duration: " + duration);

    }
}
